<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="变压器编号" prop="powerBoxNum">
        <el-input
          v-model="queryParams.powerBoxNum"
          placeholder="请输入变压器编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="安装位置" prop="install">
        <el-input
          v-model="queryParams.install"
          placeholder="请输入安装位置"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="园区编号" prop="parkNum">
        <el-input
          v-model="queryParams.parkNum"
          placeholder="请输入园区编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="使用情况" prop="useState">
        <el-input
          v-model="queryParams.useState"
          placeholder="请输入使用情况"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['energy:nyTransformerAccount:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['energy:nyTransformerAccount:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['energy:nyTransformerAccount:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['energy:nyTransformerAccount:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="nyTransformerAccountList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="变压器编号" align="center" prop="powerBoxNum" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="使用单位" align="center" prop="useUnit" />
      <el-table-column label="空开编号" align="center" prop="openNum" />
      <el-table-column label="型号" align="center" prop="modal" />
      <el-table-column label="单位" align="center" prop="unit" />
      <el-table-column label="数量" align="center" prop="amount" />
      <el-table-column label="线径" align="center" prop="cableSize" />
      <el-table-column label="安装位置" align="center" prop="install" />
      <el-table-column label="园区编号" align="center" prop="parkNum" />
      <el-table-column label="使用情况" align="center" prop="useState" />
      <el-table-column label="审批负荷" align="center" prop="approvalLoad" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['energy:nyTransformerAccount:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['energy:nyTransformerAccount:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改变压器部件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="变压器编号" prop="powerBoxNum">
          <el-input v-model="form.powerBoxNum" placeholder="请输入变压器编号" />
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入名称" />
        </el-form-item>
        <el-form-item label="使用单位" prop="useUnit">
          <el-input v-model="form.useUnit" placeholder="请输入使用单位" />
        </el-form-item>
        <el-form-item label="空开编号" prop="openNum">
          <el-input v-model="form.openNum" placeholder="请输入空开编号" />
        </el-form-item>
        <el-form-item label="型号" prop="modal">
          <el-input v-model="form.modal" placeholder="请输入型号" />
        </el-form-item>
        <el-form-item label="单位" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="数量" prop="amount">
          <el-input v-model="form.amount" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="线径" prop="cableSize">
          <el-input v-model="form.cableSize" placeholder="请输入线径" />
        </el-form-item>
        <el-form-item label="安装位置" prop="install">
          <el-input v-model="form.install" placeholder="请输入安装位置" />
        </el-form-item>
        <el-form-item label="园区编号" prop="parkNum">
          <el-input v-model="form.parkNum" placeholder="请输入园区编号" />
        </el-form-item>
        <el-form-item label="使用情况" prop="useState">
          <el-input v-model="form.useState" placeholder="请输入使用情况" />
        </el-form-item>
        <el-form-item label="审批负荷" prop="approvalLoad">
          <el-input v-model="form.approvalLoad" placeholder="请输入审批负荷" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listNyTransformerAccount, getNyTransformerAccount, delNyTransformerAccount, addNyTransformerAccount, updateNyTransformerAccount } from "@/api/smartParks/energy/nyTransformerAccount";

export default {
  name: "NyTransformerAccount",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 变压器部件表格数据
      nyTransformerAccountList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        powerBoxNum: null,
        name: null,
        install: null,
        parkNum: null,
        useState: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询变压器部件列表 */
    getList() {
      this.loading = true;
      listNyTransformerAccount(this.queryParams).then(response => {
        this.nyTransformerAccountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        powerBoxNum: null,
        name: null,
        useUnit: null,
        openNum: null,
        modal: null,
        unit: null,
        amount: null,
        cableSize: null,
        install: null,
        parkNum: null,
        useState: null,
        approvalLoad: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加变压器部件";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getNyTransformerAccount(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改变压器部件";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateNyTransformerAccount(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNyTransformerAccount(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除变压器部件编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNyTransformerAccount(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('energy/nyTransformerAccount/export', {
        ...this.queryParams
      }, `energy_nyTransformerAccount.xlsx`)
    }
  }
};
</script>
